package com.ptmall.app.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.bean.OrderBean;
import com.ptmall.app.bean.ProductBean;
import com.ptmall.app.utils.GlideUtil;
import com.ptmall.app.utils.TimeUtil;

import java.util.List;


/**
 * Created by Administrator on 2018/1/12.
 */

public class OrderGoodAdapter extends BaseAdapter {

    private Context mContext;
    private List<ProductBean> mDataList;
    private LayoutInflater mLayoutInflater;

    public OrderGoodAdapter(Context context, List<ProductBean> list) {
        this.mContext = context;
        this.mDataList = list;
        this.mLayoutInflater = LayoutInflater.from(mContext);
    }

    public void pushData(List<ProductBean> list){
        this.mDataList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if(mDataList == null){
            return 0;
        }
        return mDataList.size();
    }


    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (null == convertView) {
            convertView = mLayoutInflater.inflate(R.layout.item_ordergood,  parent,false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        ProductBean bean = mDataList.get(position);

        GlideUtil.showImg(mContext,bean.goods_cover,viewHolder.goodimg);
        viewHolder.goodprice.setText("￥"+bean.price);
        viewHolder.goodguige.setText(bean.specs_name+"");
        viewHolder.goodname.setText(bean.goods_title+"");
        viewHolder.goodnum.setText("X"+bean.num);


        return convertView;
    }

    class ViewHolder {
        ImageView goodimg;
        TextView goodname,goodguige,goodprice,goodnum;

        ViewHolder(View view) {
            goodimg = (ImageView) view.findViewById(R.id.goodimg);
            goodname = (TextView) view.findViewById(R.id.goodname);
            goodguige = (TextView) view.findViewById(R.id.goodguige);
            goodprice = (TextView) view.findViewById(R.id.goodprice);
            goodnum = (TextView) view.findViewById(R.id.goodnum);
        }
    }

}
